-include Makefile.local
# Makefile.local defines (or not) the following:
# MAC
# USESSE
# CHECKRESULT
# OUTDIR
# RELEASE

ifdef PTHREADS
BINDIR = ../thr
CFLAGS += -D__USE_PTHREADS__ -pthread
LFLAGS += -pthread
else
BINDIR = ../bin
endif

ifdef VERBOSE
CFLAGS += -D__VERBOSE__
endif

ifdef CPUTIME
CFLAGS += -D__CPUTIME__
endif

ifdef NOTIMEDRUNS
CFLAGS += -D__NOTIMEDRUNS__
endif

ifdef CHECKRESULT
CFLAGS += -D__CHECK_SPMV_RESULT__
endif

ifdef MAC
CFLAGS += -I/opt/local/include/
CFLAGS += -D__MAC_OSX__
endif

ifndef MAC
CFLAGS += -I/tools/local/include/
LFLAGS  = -lrt
endif

ifdef USESSE
CFLAGS += -D__USE_SSE__
CFLAGS += -fasm-blocks
endif


ifdef RELEASE
CFLAGS    += -Wall -O3 -mtune=core2 -march=core2 -mfpmath=sse -msse2 -ffast-math -fstrict-aliasing
else
CFLAGS    += -Wall -ggdb -fno-inline -DLOCAL_DEBUG_ENABLED -mtune=core2 -march=core2 -mfpmath=sse
endif
LFLAGS += -Wall

INCLUDES  = -I.
CC = g++

OBJDIR  = ../obj

all: dirs $(BINDIR)/dagSpMV $(BINDIR)/Mtx2Dag $(BINDIR)/Dag2Mtx $(BINDIR)/unz $(BINDIR)/MtxDiff
  
.PHONY: dirs clean

$(BINDIR)/Dag2Mtx: $(OBJDIR)/Dag2Mtx.o $(OBJDIR)/DagLoader.o $(OBJDIR)/TimeDiff.o $(OBJDIR)/BasicDagLibrary.o $(OBJDIR)/MallocAlign.o
	$(CC) -o $(BINDIR)/Dag2Mtx $(LFLAGS) $(OBJDIR)/Dag2Mtx.o $(OBJDIR)/DagLoader.o $(OBJDIR)/TimeDiff.o $(OBJDIR)/BasicDagLibrary.o $(OBJDIR)/MallocAlign.o

$(BINDIR)/Mtx2Dag: $(OBJDIR)/Mtx2Dag.o $(OBJDIR)/LoadMatrix.o $(OBJDIR)/TimeDiff.o $(OBJDIR)/BasicDagLibrary.o $(OBJDIR)/Statistics.o $(OBJDIR)/DagMtx.o $(OBJDIR)/DedupMem.o $(OBJDIR)/IteratorRegister.o
	$(CC) -o $(BINDIR)/Mtx2Dag $(LFLAGS) $(OBJDIR)/Mtx2Dag.o $(OBJDIR)/LoadMatrix.o $(OBJDIR)/TimeDiff.o $(OBJDIR)/BasicDagLibrary.o $(OBJDIR)/Statistics.o $(OBJDIR)/DagMtx.o $(OBJDIR)/DedupMem.o $(OBJDIR)/IteratorRegister.o

$(BINDIR)/dagSpMV: $(OBJDIR)/TimeDiff.o $(OBJDIR)/MallocAlign.o $(OBJDIR)/DagLoader.o $(OBJDIR)/Kernels.o $(OBJDIR)/dagSpMV.o $(OBJDIR)/BasicDagLibrary.o $(OBJDIR)/QTSKernel.o
	$(CC) -o $(BINDIR)/dagSpMV $(LFLAGS) $(OBJDIR)/dagSpMV.o $(OBJDIR)/MallocAlign.o $(OBJDIR)/DagLoader.o $(OBJDIR)/TimeDiff.o $(OBJDIR)/Kernels.o $(OBJDIR)/BasicDagLibrary.o $(OBJDIR)/QTSKernel.o

$(BINDIR)/unz: $(OBJDIR)/BasicDagLibrary.o $(OBJDIR)/unz.o $(OBJDIR)/TimeDiff.o $(OBJDIR)/LoadMatrix.o
	$(CC) -o $(BINDIR)/unz $(LFLAGS) $(OBJDIR)/unz.o $(OBJDIR)/BasicDagLibrary.o $(OBJDIR)/TimeDiff.o $(OBJDIR)/LoadMatrix.o

$(BINDIR)/MtxDiff: $(OBJDIR)/MtxDiff.o $(OBJDIR)/LoadMatrix.o $(OBJDIR)/BasicDagLibrary.o
	$(CC) -o $(BINDIR)/MtxDiff $(LFLAGS) $(OBJDIR)/MtxDiff.o $(OBJDIR)/LoadMatrix.o $(OBJDIR)/BasicDagLibrary.o

$(OBJDIR)/MtxDiff.o: MtxDiff.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c MtxDiff.cpp -o $(OBJDIR)/MtxDiff.o

$(OBJDIR)/unz.o: unz.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c unz.cpp -o $(OBJDIR)/unz.o

$(OBJDIR)/DedupMem.o: DedupMem.cpp DedupMem.h
	$(CC) $(CFLAGS) $(INCLUDES) -c DedupMem.cpp -o $(OBJDIR)/DedupMem.o

$(OBJDIR)/IteratorRegister.o: IteratorRegister.cpp IteratorRegister.h
	$(CC) $(CFLAGS) $(INCLUDES) -c IteratorRegister.cpp -o $(OBJDIR)/IteratorRegister.o

$(OBJDIR)/Dag2Mtx.o: Dag2Mtx.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c Dag2Mtx.cpp -o $(OBJDIR)/Dag2Mtx.o

$(OBJDIR)/DagMtx.o: DagMtx.cpp DagMtx.h
	$(CC) $(CFLAGS) $(INCLUDES) -c DagMtx.cpp -o $(OBJDIR)/DagMtx.o

$(OBJDIR)/Mtx2Dag.o: Mtx2Dag.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c Mtx2Dag.cpp -o $(OBJDIR)/Mtx2Dag.o

$(OBJDIR)/LoadMatrix.o: LoadMatrix.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c LoadMatrix.cpp -o $(OBJDIR)/LoadMatrix.o

$(OBJDIR)/dagSpMV.o: dagSpMV.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c dagSpMV.cpp -o $(OBJDIR)/dagSpMV.o

$(OBJDIR)/MallocAlign.o: MallocAlign.c
	$(CC) $(CFLAGS) $(INCLUDES) -c MallocAlign.c -o $(OBJDIR)/MallocAlign.o

$(OBJDIR)/Statistics.o: Statistics.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c Statistics.cpp -o $(OBJDIR)/Statistics.o

$(OBJDIR)/QTSKernel.o: QTSKernel.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c QTSKernel.cpp -o $(OBJDIR)/QTSKernel.o

$(OBJDIR)/Kernels.o: Kernels.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c Kernels.cpp -o $(OBJDIR)/Kernels.o

$(OBJDIR)/DagLoader.o: DagLoader.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c DagLoader.cpp -o $(OBJDIR)/DagLoader.o

$(OBJDIR)/TimeDiff.o: TimeDiff.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c TimeDiff.cpp -o $(OBJDIR)/TimeDiff.o

$(OBJDIR)/BasicDagLibrary.o: BasicDagLibrary.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c BasicDagLibrary.cpp -o $(OBJDIR)/BasicDagLibrary.o

dirs:
	mkdir -p $(BINDIR)
	mkdir -p $(OBJDIR)

clean:
	\rm -f $(OBJDIR)/*
	\rm -f $(BINDIR)/*
	\rm -f *~
	\rm -f *.o
	\rm -f y_hcoo.mtx
	\rm -f x_hcoo.mtx
	\rm -f y_qts.mtx
	\rm -f x_qts.mtx

